- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8.2k
Add ARC MPU v3 & v6 support #37871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ARC MPU v3 & v6 support #37871
Conversation
| related issue #37309 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move common functionality into version-agnostic file and then do specific things in v2 & v6 files to reduce duplication of code?
Also see some minor comments.
        
          
                include/arch/arc/arch.h
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
#if (CONFIG_ARC_MPU_VER == 4) || (CONFIG_ARC_MPU_VER == 6)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2021 ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZEPHYR_ARCH_ARC_CORE_MPU_ARC_MPU_V6_INTERNAL_H_ (see v6)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why mention MPUv2 in code for MPUv6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Yuguo,
please find some comments (mostly minor).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return true;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one fits in 100 symbol per line limit so let's keep it in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, is it really about MPUv2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one fits in 100 symbol per line limit so let's keep it in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one fits in 100 symbol per line limit so let's keep it in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one fits in 100 symbol per line limit so let's keep it in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one fits in 100 symbol per line limit so let's keep it in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one fits in 100 symbol per line limit so let's keep it in one line.
        
          
                soc/arc/snps_nsim/Kconfig
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, Is it correct? We don't have MPU in this NSIM SoC configuration.
5e0f2ae    to
    36ad8bd      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a couple of style nitpicks LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly I don't like these cryptic numbers. I guess these are some groups of bits shifted left?
Look at BIT_MASK() in https://github.com/zephyrproject-rtos/zephyr/blob/main/include/sys/util_macro.h#L68. Then we'll get something like BIT_MASK(xxx) << yyy which is much more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe BIT(x) and ~BIT(x) correspondigly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BIT(0)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we use r_index only in loop probably it's better to define it in loop itself:
for (int r_index = 0; r_index < get_num_regions(); r_index++) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to split definition and declaration here. Let's combine it:
/* comment */
int r_index = num_regions - mpu_config.num_regions;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't exceed the Zephyr line limit here (100 symbols per line), please keep it in one line.
Please check rest of the code - we have a lot of places where we can put the whole expression in one line. It improves code readability a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we move those magic numbers to some defines / constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would be enough to also use much simpler understood BIT_MASK(2) & BIT_MASK(3) << 9 here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still It would be better to have all this shift values named. For example we can use "AUX_MPU_REGxx_FIELDxx_SHIFT"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we use i only in loop probably it's better to define it in loop itself:
for (uint32_t i = 0U; i < r_index; i++) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
489f934    to
    43ac849      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit titles it's better to say "add support of" instead of "to".
Also some comments below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you don't like #define AUX_MPU_RDP_ATTR_MASK (BIT_MASK(6) << 3)? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here #define AUX_MPU_RDP_SIZE_MASK (BIT_MASK(3) << 9 | BIT_MASK(2))?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would be enough to also use much simpler understood BIT_MASK(2) & BIT_MASK(3) << 9 here.
| @YuguoWH could you please also add the nSIM board with v6 MPU so we can easily test it in our verification / manually? | 
f943954    to
    8cdf600      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With 2 nitpicks LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use BIT_MASK here as well as in the next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then it would be:
#define AUX_MPU_RDP_REGION_SIZE(size)  (((size - 1) & BIT_MASK(2)) | \ (((size - 1) & (BIT_MASK(3) << 2)) << 7))
I think it looks more complex...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Add support of ARC mpu version 3 which can have region size down to 32 bytes Signed-off-by: Yuguo Zou <[email protected]>
| Hi @evgeniy-paltsev , PR rebased, thanks. | 
Add support of ARC mpu v6 * minimal region size down to 32 bytes * maximal region number up to 32 * not support uncacheable region and volatile uncached region * clean up mpu code for better readablity Signed-off-by: Yuguo Zou <[email protected]>
We add support of mpu v6 therefore it is needed to have a board to validate that feature. This commit add a new HS nsim simulator which supports mpu v6. Signed-off-by: Yuguo Zou <[email protected]>
| @nashif could you please pick this one up for v2.7? | 
| config SOC_NSIM_HS_MPUV6 | ||
| bool "Synopsys ARC HS with MPU v6 in nSIM" | ||
| select CPU_HAS_MPU | ||
| select CPU_HAS_FPU | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is FPU enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I keep it same with other NSIM_HS boards, so FPU is enabled
Adding ARC MPU v3 and v6 support.
The v3 uses same logic with v2 and the only difference is to support 32 bytes minimal region size.
The v6 support 32 bytes, and it can have up to 32 regions. The regions are divided into 2 banks and switched by set/unset RB bit in MPU_EN aux register
This PR also introduces a new nsim hs board simulator which can validate/test with mpu v6.